package com.shuoyue.ycgk.ui.recruitment.job;

import com.shuoyue.ycgk.base.BasePresenter;
import com.shuoyue.ycgk.base.BaseResult;
import com.shuoyue.ycgk.base.BaseView;
import com.shuoyue.ycgk.base.ListWithPage;
import com.shuoyue.ycgk.entity.JobInfo;
import com.shuoyue.ycgk.net.RetrofitClient;
import com.shuoyue.ycgk.net.base.ApiSubscriber;
import com.shuoyue.ycgk.net.gsondefaultadapter.Optional;

import io.reactivex.Observable;

public interface JobContract {
    interface View extends BaseView {

        void setJobList(ListWithPage<JobInfo> list);
    }

    class Presenter extends BasePresenter<View> {
        Model model = new Model();

        public void getJobs(Integer modelId, Integer examId, int page, String title) {
            apply(model.getJobs(modelId, examId, page, title))
                    .subscribe(new ApiSubscriber<Optional<ListWithPage<JobInfo>>>(mView, this) {
                        @Override
                        public void onNext(Optional<ListWithPage<JobInfo>> data) {
                            super.onNext(data);
                            mView.setJobList(data.getIncludeNull());
                        }
                    });
        }
    }

    class Model {


        public Observable<BaseResult<ListWithPage<JobInfo>>> getJobs(Integer modelId, Integer id, int page, String title) {
            return RetrofitClient.getInstance().getApi().getRecJobs(null, id, page, title);
        }
    }
}
